<?php
/**
 * tpAdmin [a web admin based ThinkPHP5]
 *
 * @author yuan1994 <tianpian0805@gmail.com>
 * @link http://tpadmin.yuan1994.com/
 * @copyright 2016 yuan1994 all rights reserved.
 * @license http://www.apache.org/licenses/LICENSE-2.0
 */

//------------------------
// 会员配置
//-------------------------

namespace app\admin\controller;

use app\admin\Controller;
use think\Db;


class Agreement extends Controller
{
    //协议列表
    public function index()
    {
        $list = Db::name('agreement')->select();
        return view('agreement/index', [
            'list' => $list
        ]);
    }

    //协议
    public function edit()
    {
        if ($this->request->post()) {
            $data = input('post.');
            $info['content'] = $data['editorValue'];
            $result = Db::name('agreement')->where(['id' => $data['id']])->update($info);
            if ($result === false) {
                return ajax_return_error('失败');
            }
            return ajax_return_adv('成功');
        } else {
            $info = Db::name('agreement')->where(['id' => input('id')])->find();
            return view('agreement/edit', ['info' => $info]);
        }
    }
}